<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <title>启动</title>
  <link href="/static/css/bootstrap.min.css" rel="stylesheet"/>
  <link rel="stylesheet" href="/static/include/css/style.css">
  <style>
    .form-table .t-a-c {
      text-align: center;
    }
  </style>
</head>
<body class="white-bg" style="height: 95%" >
	<span id="info_msg">无效配置!</span>
</body>
<script src="/static/include/js/footer.js"></script>
<script>
	  $(function () {
		  debugger
		  var flowParam = parent.window || {};
		  //	action,instanceId,taskId,nodeId,data.**.字段
		  var url = getQueryString("url");
		  url = parasUrlParams(flowParam, url);
		  if (!url) {
		  	$("#info_msg").html("未配置嵌入url路径");
		  	return false;
		  }
		  window.open(url);
		  setTimeout(function() {
		  	//$.Dialog.close(this);
			$.modal.close()
		  }, 500);
	})
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var urlArr = window.location.href.split('?')
		if (urlArr.length <= 1) {
			return null
		}
		var url = urlArr[1].match(reg);
		if (url != null) {
			return decodeURIComponent(url[2])//decodeURIComponent() 函数可对 encodeURIComponent() 函数编码过的 URI 进行解码。
		} else {
			return null
		}
	}
	function parasUrlParams(map, url) {
		var pobj = new Object;
		console.log("i解析前 url==", url);
		var newUrl = url;
		//1、解析url参数键值对
		if (url.indexOf("?") != -1) {
			newUrl = url.substring(0, url.indexOf("?"));
			var pstr = url.split("?")[1];
			//	console.log("pstr=",pstr);
			if (pstr) {
				var kvs = pstr.split("&");
				for (i = 0; i < kvs.length; i++) {
					// 数据属性与数值分离
					var aParam = kvs[i].split("=");
					//console.log(aParam);
					// 使用属性括号进行属性赋值
					if (aParam.length == 2) {
						pobj[aParam[0]] = aParam[1]
					}
				}
			}
			console.log("pobj==", pobj);
			//2、替换占位符
			var keys = Object.keys(pobj);
			if (keys.length > 0) {
				keys.forEach(function(key) {
					var v = pobj[key];
					if (v.startsWith("{") && v.endsWith("}")) {
						var k = v.substring(1, v.length - 1)
						pobj[key] = getValue(map, k);
					}
				});
				console.log("占位符替换 pobj==", pobj);
				//重新组装url
				newUrl = newUrl + "?"
				keys.forEach(function(key) {
					var v = pobj[key];
					newUrl = newUrl + key + "=" + v + "&"
				});
			}
			if (newUrl.endsWith("&") || newUrl.endsWith("?")) {
				newUrl = newUrl.substring(0, newUrl.length - 1)
			}
		}
		console.log("i解析后url==", newUrl);
		return newUrl;
	}

	function getValue(map, key) {
		if (key.indexOf(".") == -1)
			return map[key];
		var keys = key.split(".");
		var temp = map;
		for (var i = 0; i < keys.length; i++) {
			var k = keys[i];
			if (temp.hasOwnProperty(k)) {
				temp = temp[k];
			} else {
				console.log("参数配置错误：{" + key + "}中配置的" + k + "不存在")
				return "";
			}
		}
		return temp;
	}
</script>

</html>